#include<bits/stdc++.h>
using std::cin;
using std::cout;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using pii = std::pair<int, int>;
#define TESTS int _; std::cin >> _; while(_--)
#define all(a) a.begin(), a.end()
#define pb push_back
#define fi first
#define se second
#define SUM(v) std::accumulate(all(v), 0LL);
#define MIN(v) *std::min_element(all(v));
#define MAX(v) *std::max_element(all(v));
#define UNIQUE(v) std::sort(all(v)), v.erase(std::unique(all(v), v.end()));


constexpr i64 inf = 1E18, Md3 = 998244353, Md7 = 1e9 + 7;
//std::mt19937 rng {std::chrono::steady_clock::now().time_since_epoch().count()};

int main() {
	
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	int m;
	std::cin >> m;
	std::vector<int> pow(11);
	pow[0] = 1;
	for(int i = 1; i <= 10; i++) {
		pow[i] = pow[i - 1] * 3;
	}
	std::vector<int> ans;
	for(int i = 10; i >= 0; i--) {
		while(m >= pow[i]) {
			ans.push_back(i);
			m -= pow[i];
		}
	}
	std::cout << ans.size() << "\n";
	
	for(auto x : ans) {
		std::cout << x << " ";
	}

	return 0;
}